﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Linq;
using AdminModule.IndexMarkServiceReference;
using SharedCode;

namespace AdminModule.ViewModels
{
    public class EditJobsVM : ViewModelBase
    {
        private IndexMarkServiceClient client = new IndexMarkServiceClient();

        public EditJobsVM()
        {
            client.GetAdmPositionsCompleted +=new EventHandler<GetAdmPositionsCompletedEventArgs>(client_GetAdmPositionsCompleted);
            client.GetAdmStatusesCompleted +=new EventHandler<GetAdmStatusesCompletedEventArgs>(client_GetAdmStatusesCompleted);
            base.LoadCompleted += new LoadEventHandler(EditJobsVM_LoadCompleted);
        }

        public override void Init()
        {
            base.Init();
            this.LoadAdmPosition();
        }

        void EditJobsVM_LoadCompleted(object sender, LoadEventArgs e)
        {
            if (e.Type == typeof(AdmPosition))
            {
                client.GetAdmStatusesAsync();
            }
            if (e.Type == typeof(AdmStatus))
            {
                base.RaiseInitCompleted();
            }
        }

        #region Должности
        private ObservableCollection<AdmPosition> positions = new ObservableCollection<AdmPosition>();
        public ObservableCollection<AdmPosition> AdmPositionCollection
        {
            get
            {
                return this.positions;
            }
            set
            {
                this.positions = value;
            }
        }

        void client_GetAdmPositionsCompleted(object sender, GetAdmPositionsCompletedEventArgs e)
        {
            positions.Clear();
            foreach (var s in e.Result)
            {
                positions.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmPosition));
        }

        public void LoadAdmPosition()
        {
            client.GetAdmPositionsAsync();
        }
        #endregion

        #region Ставки
        private ObservableCollection<AdmStatus> statuses = new ObservableCollection<AdmStatus>();
        public ObservableCollection<AdmStatus> AdmStatusCollection
        {
            get
            {
                return this.statuses;
            }
            set
            {
                this.statuses = value;
            }
        }

        void client_GetAdmStatusesCompleted(object sender, GetAdmStatusesCompletedEventArgs e)
        {
            statuses.Clear();
            foreach (var s in e.Result)
            {
                statuses.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmStatus));
        }

        public void LoadAdmStatus()
        {
            client.GetAdmStatusesAsync();
        }
        #endregion
    }
}
